using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Data; 
using System.Data.SqlClient; 
using System.Data.SqlTypes; 
using SolucionUtiles; 
using SolucionEntidad; 
namespace SolucionDatos 
{ 
   public class PermisoxrolDao 
    { 
        private SqlConnection cn; 
        public PermisoxrolDao(SqlConnection cn) 
        { 
           this.cn = cn; 
        } 
        public void insert(Permisoxrol obj)
        { 
           SqlCommand command = new SqlCommand("INSERT INTO permisoxrol " + 
           "(idRol,idPermisos) VALUES" + 
           "(@idRol,@idPermisos)", this.cn); 

command.Parameters.Add(new SqlParameter("@idRol", obj.idRol)); 
command.Parameters.Add(new SqlParameter("@idPermisos", obj.idPermisos)); 
command.ExecuteNonQuery(); 
} 
  		public void update(Permisoxrol obj) 
    	{ 
        	SqlCommand command = new SqlCommand("UPDATE Permisoxrol " + 
			" SET " + 
 " WHERE " + 
"idRol=@idRol" 
+" AND idPermisos=@idPermisos" 
,this.cn); 
command.Parameters.Add(new SqlParameter("@idRol", obj.idRol)); 
command.Parameters.Add(new SqlParameter("@idPermisos", obj.idPermisos)); 
command.ExecuteNonQuery(); 
} 
       public void delete(Permisoxrol obj){ 
SqlCommand command = new SqlCommand("DELETE FROM permisoxrol WHERE "  
 +"idRol=@idRol" 
+" AND idPermisos=@idPermisos" 
, this.cn); 
command.Parameters.Add(new SqlParameter("@idRol", obj.idRol)); 
command.Parameters.Add(new SqlParameter("@idPermisos", obj.idPermisos)); 
command.ExecuteNonQuery(); 
} 
        public Permisoxrol get(Permisoxrol obj) 
{ 
   Permisoxrol record = null; 
    SqlCommand command = new SqlCommand("SELECT idRol,idPermisos FROM permisoxrol where " 
 +"idRol=@idRol" 
+" AND idPermisos=@idPermisos" 
, this.cn); 
command.Parameters.Add(new SqlParameter("@idRol", obj.idRol)); 
command.Parameters.Add(new SqlParameter("@idPermisos", obj.idPermisos)); 

    SqlDataReader dr = command.ExecuteReader();
dr.Read(); 
record = new Permisoxrol(); 
if (dr["idRol"] == DBNull.Value) { record.idRol = SqlInt32.Null; } else { record.idRol = (Int32)dr["idRol"]; } 
if (dr["idPermisos"] == DBNull.Value) { record.idPermisos = SqlInt32.Null; } else { record.idPermisos = (Int32)dr["idPermisos"]; } 
this.cn.Close(); 
return record; 
} 
     public List<Permisoxrol> getList() 
{ 
   List<Permisoxrol> list = new List<Permisoxrol>(); 
    SqlCommand command = new SqlCommand("SELECT idRol,idPermisos FROM permisoxrol", this.cn); 
    SqlDataReader dr = command.ExecuteReader(); 
    while (dr.Read()) 
    { 
Permisoxrol obj = new Permisoxrol(); 
if (dr["idRol"] == DBNull.Value) { obj.idRol = SqlInt32.Null; } else { obj.idRol = (Int32)dr["idRol"]; } 
if (dr["idPermisos"] == DBNull.Value) { obj.idPermisos = SqlInt32.Null; } else { obj.idPermisos = (Int32)dr["idPermisos"]; } 
list.Add(obj); 
} 
return list; 
} 
} 
} 
